using System;
using System.Data;
using System.Configuration;
using System.Web;
using PccCommonForC;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Collections;
using System.Text;
using System.Collections.Generic;


namespace db_ShowRoom
{
    public class db_menu:PccCommonForC.DbBaseObject
    {
        public db_menu(): base(){}

        private string strcn;
        private SqlConnection cn;
        public db_menu(string mconnect)
        {
            m_ConnectionString = mconnect;
            m_Conn = new SqlConnection(mconnect);
        }

        #region "Get menu Left"
        //Get list Menu cha
        public DataSet db_GetPowersUser(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string myType = myMsg.Query("Type").ToString().Trim();
            if (user_id == "")
                user_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@user_id",SqlDbType.Int),
                                            new SqlParameter("@Type",SqlDbType.Char,1)
										};

            parameters[0].Value = user_id;
            parameters[1].Value = myType;
            ds = RunProcedure("Pro_GetPowersUser", parameters, "GetPowersUser");
            return ds;
        }
        #endregion

        

        #region "InsUpd Menu Manager"
        //Nguyen Huu Minh
        //2010/06/01
        // InsUpdMenu
        public string db_InsUpdMenu(string strXML)
        {
            PccMsg myMsg = new PccMsg(strXML);
            string menu_id = myMsg.Query("menu_id").ToString().Trim();
            string menu_name = myMsg.Query("menu_name").ToString().Trim();
            string menu_link = myMsg.Query("menu_link").ToString().Trim();
            string up_id = myMsg.Query("up_id").ToString().Trim();
            string User_Name = myMsg.Query("User_Name").ToString().Trim();
            string decen = myMsg.Query("decen").ToString().Trim();
            string Active = myMsg.Query("Active").ToString().Trim();
            string chk_mk = myMsg.Query("chk_mk").ToString().Trim();
            string brand_id = myMsg.Query("brand_id").ToString().Trim();
            string myType = myMsg.Query("Type").ToString().Trim();
            
            if (menu_id == "")
                menu_id = "0";
            if (decen == "")
                decen = "0";
            if (up_id == "")
                up_id = "0";
            if (brand_id == "")
                brand_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@menu_id",SqlDbType.Int),  
                                            new SqlParameter("@menu_name",SqlDbType.NVarChar,50),
                                            new SqlParameter("@menu_link",SqlDbType.NVarChar,100),  
											new SqlParameter("@up_id",SqlDbType.Decimal,12),             
                                            new SqlParameter("@User_Name",SqlDbType.NVarChar,50),                                         
                                            new SqlParameter("@decen",SqlDbType.Int),  
                                            new SqlParameter("@Active",SqlDbType.Int),
                                            new SqlParameter("@chk_mk",SqlDbType.Char,1),
                                            new SqlParameter("@brand_id",SqlDbType.Int),  
                                            new SqlParameter("@Type",SqlDbType.Char,1),
											new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};

            parameters[0].Value = Convert.ToInt32(menu_id);
            parameters[1].Value = menu_name;
            parameters[2].Value = menu_link;
            parameters[3].Value = Convert.ToInt32(up_id);
            parameters[4].Value = User_Name;
            parameters[5].Value = Convert.ToInt32(decen);
            parameters[6].Value = Active;
            parameters[7].Value = chk_mk;
            parameters[8].Value = brand_id;
            parameters[9].Value = myType;
            parameters[10].Direction = ParameterDirection.Output;

            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_InsUpdMenu", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[10].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;
        }
        #endregion

        #region "InsUpd power user"
        //Nguyen Huu Minh
        //2010/06/01
        // InsUpdMenu
        public string db_InsUpdPowerUser(string strXML)
        {
            PccMsg myMsg = new PccMsg(strXML);
            string mn_id_d = myMsg.Query("mn_id_d").ToString().Trim();
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string mn_id = myMsg.Query("mn_id").ToString().Trim();
            string chk_view = myMsg.Query("chk_view").ToString().Trim();
            string chk_add = myMsg.Query("chk_add").ToString().Trim();
            string chk_edit = myMsg.Query("chk_edit").ToString().Trim();
            string chk_del = myMsg.Query("chk_del").ToString().Trim();
            string myType = myMsg.Query("Type").ToString().Trim();

            if (mn_id_d == "")
                mn_id_d = "0";
            if (user_id == "")
                user_id = "0";
            if (mn_id == "")
                mn_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@mn_id_d",SqlDbType.Int),  
                                            new SqlParameter("@user_id",SqlDbType.Int),  
                                            new SqlParameter("@mn_id",SqlDbType.Int),  
                                            new SqlParameter("@chk_view",SqlDbType.Char,1),
                                            new SqlParameter("@chk_add",SqlDbType.Char,1),
                                            new SqlParameter("@chk_edit",SqlDbType.Char,1),
                                            new SqlParameter("@chk_del",SqlDbType.Char,1),
                                            new SqlParameter("@Type",SqlDbType.Char,1),
											new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};

            parameters[0].Value = mn_id_d;
            parameters[1].Value = user_id;
            parameters[2].Value = mn_id;
            parameters[3].Value = chk_view;
            parameters[4].Value = chk_add;
            parameters[5].Value = chk_edit;
            parameters[6].Value = chk_del;
            parameters[7].Value = myType;
            parameters[8].Direction = ParameterDirection.Output;

            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_IsUpdPowerUser2", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[8].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;
        }
        #endregion

        #region "InsUpd menu admin"
        //Nguyen Huu Minh
        //2010/06/01
        // InsUpdMenu

        public string db_InsUpdMenuAdmin(string strXML)
        {
            PccMsg myMsg = new PccMsg(strXML);
            string mn_id = myMsg.Query("mn_id").ToString().Trim();
            string mn_nm = myMsg.Query("mn_nm").ToString().Trim();
            string link = myMsg.Query("link").ToString().Trim();
            string status = myMsg.Query("status").ToString().Trim();
            string upd_id = myMsg.Query("upd_id").ToString().Trim();
            string myType = myMsg.Query("Type").ToString().Trim();

            if (upd_id == "")
                upd_id = "0";
           
            if (mn_id == "")
                mn_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@mn_id",SqlDbType.Int),  
                                            new SqlParameter("@mn_nm",SqlDbType.NVarChar,500),  
                                            new SqlParameter("@link",SqlDbType.NVarChar,500),  
                                            new SqlParameter("@status",SqlDbType.Char,1),
                                            new SqlParameter("@upd_id",SqlDbType.Int),
                                            new SqlParameter("@Type",SqlDbType.Char,1),
											new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};

            parameters[0].Value = mn_id;
            parameters[1].Value = mn_nm;
            parameters[2].Value = link;
            parameters[3].Value = status;
            parameters[4].Value = upd_id;
            parameters[5].Value = myType;
            parameters[6].Direction = ParameterDirection.Output;

            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_IsUpdMenuAdmin", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[6].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;
        }
        #endregion

        #region "Get GetMenuAdminBySearch"
        //Get list Menu cha
        public DataSet GetMenuAdminBySearch(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string mn_id = myMsg.Query("mn_id").ToString().Trim();
            string mn_nm = myMsg.Query("mn_nm").ToString().Trim();
            string status = myMsg.Query("status").ToString().Trim();
            if (mn_id == "")
                mn_id = "0";
            SqlParameter[] parameters = { 
                                            new SqlParameter("@mn_id",SqlDbType.Int),
                                            new SqlParameter("@mn_nm",SqlDbType.NVarChar,500),
                                             new SqlParameter("@status",SqlDbType.Char,1)
										};
            parameters[0].Value = mn_id;
            parameters[1].Value = mn_nm;
            parameters[2].Value = status;
            ds = RunProcedure("Pro_GetListMenuAdminBySearch", parameters, "GetListMenuAdminBySearch");
            return ds;
        }
        #endregion
    }
}
